//
//  STTableViewCell.swift
//  Demo-04-TabBarTest
//
//  Created by 苏统世 on 16/5/16.
//  Copyright © 2016年 SuTon. All rights reserved.
//

import UIKit

class STTableViewCell: UITableViewCell {

    var data:STData?{
        didSet{
            topView.data = data
            retweetView.retweetStatus = data?.retweeted_status
        }
    }
    
    lazy private var topView:STTopView = STTopView()
    lazy private var bottomView:STBottomView = STBottomView()
    lazy private var retweetView:STRetweetView = STRetweetView()
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }

    private func setupUI(){
        
//        backgroundColor=UIColor.redColor()
        
        self.contentView.addSubview(topView)
        self.contentView.addSubview(retweetView)
        self.contentView.addSubview(bottomView)
        
        
        topView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView).offset(cellMargin)
            make.leading.trailing.equalTo(contentView)
        }
        retweetView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(topView.snp_bottom)
            make.leading.equalTo(contentView).offset(cellMargin)
            make.trailing.equalTo(contentView).offset(-cellMargin)
//            make.size.equalTo(CGSize(width: 359, height: 359))
        }
        bottomView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetView.snp_bottom)
            make.trailing.leading.equalTo(contentView)
            make.height.equalTo(30)
        }
        
        // 根据cell的约束自动计算行高,系统是去获取contentView的高度作为cell的高度
        contentView.snp_makeConstraints { (make) -> Void in
            make.top.leading.trailing.equalTo(self)
            make.bottom.equalTo(bottomView)
        }
    }
}
